//
//  SAMemberTopUpRecordCell.m
//  saasRetail
//
//  Created by mac on 2023/3/8.
//

#import "SAMemberTopUpRecordCell.h"
#import "SAMemberTopUpRecordModel.h"
#import "UILabel+NSMutableAttributedString.h"

@interface SAMemberTopUpRecordCell()

@property (nonatomic, strong) UILabel *titleLab;
@property (nonatomic, strong) UILabel *totalLab;
@property (nonatomic, strong) UILabel *vipLab;
@property (nonatomic, strong) UILabel *dateLab;

@end

@implementation SAMemberTopUpRecordCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if(self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]){
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self initUI];
    }
    return self;
}

-(void)setModel:(SAMemberTopUpRecordModel *)model {
    _model = model;
    NSArray *titleArr = @[@"无", @"现金", @"刷卡", @"汇款", @"微信", @"支付宝"];
    int rechargeType = model.rechargeType.intValue;
    self.titleLab.text = @"充值方式：";
    if (rechargeType > -1 && rechargeType < 6) {
        self.titleLab.text = [NSString stringWithFormat:@"充值方式：%@",titleArr[rechargeType]];
    }
    
    if (model.rechargeAmount.doubleValue > 0) {
        self.totalLab.textColor = kPinkColor;
        if (model.giveAmount.doubleValue > 0) {
            NSString *giveAmountStr = [NSString stringWithFormat:@"(赠送%0.2lf)",model.giveAmount.doubleValue/100];
            self.totalLab.text = [NSString stringWithFormat:@"+%0.2lf\n%@",model.rechargeAmount.doubleValue/100,giveAmountStr];
            [self.totalLab setAttributedStringWithSubString:giveAmountStr color:kPinkColor font:kFont(12)];
        }else {
            self.totalLab.text = [NSString stringWithFormat:@"+%0.2lf",model.rechargeAmount.doubleValue/100];
        }
    }else {
        self.totalLab.textColor = kBuleColor;
        self.totalLab.text = [NSString stringWithFormat:@"%0.2lf",model.rechargeAmount.doubleValue/100];
    }
    
    self.vipLab.text = [NSString stringWithFormat:@"会员：%@",model.memberName];
    NSString *time = model.createTime;
    if (time.length > 19) {
        time = [time substringToIndex:19];
    }
    time = [time stringByReplacingOccurrencesOfString:@"T" withString:@" "];
    self.dateLab.text = time;

}

-(void)initUI {
    [self.contentView addSubview:self.titleLab];
    [self.contentView addSubview:self.totalLab];
    [self.contentView addSubview:self.vipLab];
    [self.contentView addSubview:self.dateLab];
}

-(UILabel *)titleLab {
    if (!_titleLab) {
        _titleLab = [[UILabel alloc] initWithFrame:SARectMake(20, 0, 200, 70)];
        _titleLab.textColor = kBlackColor;
        _titleLab.font = kFont(15);
    }
    return _titleLab;
}

-(UILabel *)totalLab {
    if (!_totalLab) {
        _totalLab = [[UILabel alloc] initWithFrame:SARectMake(100, 0, 175, 70)];
        _totalLab.textColor = kPinkColor;
        _totalLab.font = kFont(15);
        _totalLab.textAlignment = NSTextAlignmentCenter;
        _totalLab.numberOfLines = 0;
    }
    return _totalLab;
}

-(UILabel *)vipLab {
    if (!_vipLab) {
        _vipLab = [[UILabel alloc] initWithFrame:SARectMake(kScreenWidth - 170, 15, 150, 20)];
        _vipLab.textColor = kBlackColor;
        _vipLab.font = kFont(15);
        _vipLab.textAlignment = NSTextAlignmentRight;
    }
    return _vipLab;
}

-(UILabel *)dateLab {
    if (!_dateLab) {
        _dateLab = [[UILabel alloc] initWithFrame:SARectMake(kScreenWidth - 170, 35, 150, 20)];
        _dateLab.textColor = kBlackColor;
        _dateLab.font = kFont(12);
        _dateLab.textAlignment = NSTextAlignmentRight;
    }
    return _dateLab;
}

@end
